import React, { Component } from 'react'

export default class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      message: "hello world",
    }
  }
  render() {
    return (
      <div>
        <h2>{this.state.message}</h2>
        <button onClick={e => this.chengeText()}>改变文本</button>
        <button id="btn">改变文本2</button>
      </div>
    )
  }

  componentDidMount() {
    document.getElementById("btn").onclick = () => {
      this.setState({
        message: "你好"
      })
      console.log(this.state.message);
    }
  }

  chengeText() {
    // 情况1：将setState放入定时器中
    setTimeout(() => {
      this.setState({
        message: "你好"
      })
      console.log(this.state.message);
    }, 0);



  }
}
